package com.xdemo.personal.server;

import javax.script.Bindings;
import javax.script.SimpleBindings;


import com.meetup.memcached.Logger;
import com.meetup.memcached.MemcachedClient;
import com.xdemo.core.ScriptManager;
import com.xdemo.personal.config.PersonalServerConfig;
import com.xdemo.personal.httpserver.PersonalHttpServer;
import com.xdemo.personal.socketserver.PersonalSocketServer;

public class PersonalServer {
	
	private PersonalServerConfig serverConfig = PersonalServerConfig.getInstance();

	private ScriptManager scriptManager = new ScriptManager("resource");
	
	public static void main(String[] args) {
		Logger.getLogger( MemcachedClient.class.getName() ).setLevel( Logger.LEVEL_WARN );

		PersonalServer _server = new PersonalServer();
		_server.config();
		_server.start();
	}
	
	public void config() {
		Bindings _bindings = new SimpleBindings();
		_bindings.put("server", serverConfig);
		scriptManager.runScript("server.config.js", _bindings);
	}
	
	public void start() {
		PersonalHttpServer _server = new PersonalHttpServer(serverConfig);
		_server.start();
		
		PersonalSocketServer _socketServer = new PersonalSocketServer(serverConfig);
		_socketServer.start();
	}
}
